
/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2019原作者。
 *
 *根据Apache许可证2.0版（“许可证”）获得许可；
 *除非符合许可证，否则不得使用此文件。
 *您可以在以下地址获取许可证副本：
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，软件
 *根据许可证分发的内容是按“原样”分发的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限和
 *许可证下的限制。
 */

package org.springframework.aop;

import java.lang.reflect.Method;

/**
 * Part of a {@link Pointcut}: Checks whether the target method is eligible for advice.
 *
 * <p>A MethodMatcher may be evaluated <b>statically</b> or at <b>runtime</b> (dynamically).
 * Static matching involves method and (possibly) method attributes. Dynamic matching
 * also makes arguments for a particular call available, and any effects of running
 * previous advice applying to the joinpoint.
 *
 * <p>If an implementation returns {@code false} from its {@link #isRuntime()}
 * method, evaluation can be performed statically, and the result will be the same
 * for all invocations of this method, whatever their arguments. This means that
 * if the {@link #isRuntime()} method returns {@code false}, the 3-arg
 * {@link #matches(java.lang.reflect.Method, Class, Object[])} method will never be invoked.
 *
 * <p>If an implementation returns {@code true} from its 2-arg
 * {@link #matches(java.lang.reflect.Method, Class)} method and its {@link #isRuntime()} method
 * returns {@code true}, the 3-arg {@link #matches(java.lang.reflect.Method, Class, Object[])}
 * method will be invoked <i>immediately before each potential execution of the related advice</i>,
 * to decide whether the advice should run. All previous advice, such as earlier interceptors
 * in an interceptor chain, will have run, so any state changes they have produced in
 * parameters or ThreadLocal state will be available at the time of evaluation.
 *
 * <p>Concrete implementations of this interface typically should provide proper
 * implementations of {@link Object#equals(Object)} and {@link Object#hashCode()}
 * in order to allow the matcher to be used in caching scenarios &mdash; for
 * example, in proxies generated by CGLIB.
 *
 * @author Rod Johnson
 * @since 11.11.2003
 * @see Pointcut
 * @see ClassFilter
 */
/**
 *｛@link Pointcut｝的一部分：检查目标方法是否有资格获得建议。
 *
 *<p>MethodMatcher可以在<b>静态</b>或<b>运行时</b>（动态）进行评估。
 *静态匹配涉及方法和（可能）方法属性。动态匹配
 *还使特定调用的参数可用，以及运行
 *适用于接合点的先前建议。
 *
 *＜p＞如果实现从其｛@link#isRuntime（）｝返回｛@code false｝
 *方法，可以静态执行评估，结果将相同
 *对于此方法的所有调用，无论其参数如何。这意味着
 *如果｛@link#isRuntime（）｝方法返回｛@code false｝
 *｛@link#matches（java.lang.reflect.Method，Class，Object[]）｝方法将永远不会被调用。
 *
 *＜p＞如果实现从其2-arg返回｛@code true｝
 *{@link#matches（java.lang.reflect.Method，Class）}方法及其{@link#isRuntime（）}方法
 *返回｛@code true｝，3-arg｛@link#匹配（java.lang.reflect.Method，Class，Object[]）｝
 *方法将在每次潜在执行相关建议</i>之前立即调用<i>，
 *以决定是否应执行建议。所有以前的建议，例如早期的拦截器
 *在拦截器链中，将运行，因此它们在
 *参数或ThreadLocal状态将在评估时可用。
 *
 *＜p＞此接口的具体实现通常应提供适当的
 *｛@link Object#equals（Object）｝和｛@linkObject#hashCode（）｝的实现
 *以便在缓存场景中使用匹配器&mdash；对于
 *例如在CGLIB生成的代理中。
 *
 *@作者Rod Johnson
 *@自2003年11月11日
 *@参见Pointcut
 *@参见ClassFilter
 */
public interface MethodMatcher {

	/**
	 * Perform static checking whether the given method matches.
	 * <p>If this returns {@code false} or if the {@link #isRuntime()}
	 * method returns {@code false}, no runtime check (i.e. no
	 * {@link #matches(java.lang.reflect.Method, Class, Object[])} call)
	 * will be made.
	 * @param method the candidate method
	 * @param targetClass the target class
	 * @return whether this method matches statically
	 */
	/**
	 *执行静态检查给定方法是否匹配。
	 *＜p＞如果返回｛@code false｝或｛@link#isRuntime（）｝
	 *方法返回｛@code false｝，无运行时检查（即无
	 *｛@link#matches（java.lang.reflect.Method，Class，Object[]）｝调用）
	 *将制作。
	 *@param method候选方法
	 *@param targetClass目标类
	 *@return此方法是否静态匹配
	 */
	boolean matches(Method method, Class<?> targetClass);

	/**
	 * Is this MethodMatcher dynamic, that is, must a final call be made on the
	 * {@link #matches(java.lang.reflect.Method, Class, Object[])} method at
	 * runtime even if the 2-arg matches method returns {@code true}?
	 * <p>Can be invoked when an AOP proxy is created, and need not be invoked
	 * again before each method invocation,
	 * @return whether a runtime match via the 3-arg
	 * {@link #matches(java.lang.reflect.Method, Class, Object[])} method
	 * is required if static matching passed
	 */
	/**
	 *此MethodMatcher是否是动态的，即必须对
	 *｛@link#matches（java.lang.reflect.Method，Class，Object[]）｝方法位于
	 *即使2-arg匹配方法返回｛@code true｝？
	 *＜p＞可以在创建AOP代理时调用，无需调用
	 *再次在每次方法调用之前，
	 *@return运行时是否通过3-arg匹配
	 *｛@link#matches（java.lang.reflect.Method，Class，Object[]）｝方法
	 *如果通过了静态匹配，则需要
	 */
	boolean isRuntime();

	/**
	 * Check whether there a runtime (dynamic) match for this method,
	 * which must have matched statically.
	 * <p>This method is invoked only if the 2-arg matches method returns
	 * {@code true} for the given method and target class, and if the
	 * {@link #isRuntime()} method returns {@code true}. Invoked
	 * immediately before potential running of the advice, after any
	 * advice earlier in the advice chain has run.
	 * @param method the candidate method
	 * @param targetClass the target class
	 * @param args arguments to the method
	 * @return whether there's a runtime match
	 * @see MethodMatcher#matches(Method, Class)
	 */
	/**
	 *检查此方法是否存在运行时（动态）匹配，
	 *其必须静态匹配。
	 *＜p＞只有当2-arg匹配方法返回时，才会调用此方法
	 *｛@code true｝用于给定方法和目标类，如果
	 *｛@link#isRuntime（）｝方法返回｛@code true｝。已调用
	 *在建议潜在运行之前
	 *建议链早期的建议已运行。
	 *@param method候选方法
	 *@param targetClass目标类
	 *@param args方法的参数
	 *@return是否存在运行时匹配
	 *@see MethodMatcher#matches（方法，类）
	 */
	boolean matches(Method method, Class<?> targetClass, Object... args);


	/**
	 * Canonical instance that matches all methods.
	 */
	/**
	 *匹配所有方法的标准实例。
	 */
	MethodMatcher TRUE = TrueMethodMatcher.INSTANCE;

}
